<!doctype html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Document</title>
	<style type="text/css" media="screen">
		*{
			margin: 0;
			padding: 0;
		}	
		.add{
			width: 600px;
			height: 400px;
			background: #ccc;
			position: absolute;
			left: 380px;
			top: 80px;
		}
		.add ul{
			list-style: none;
			width: 80%;
			height:60%;
			margin: 0 auto;
			text-align: center;
		}
		.add li{
			text-align: center;
			height: 20%;
			line-height: 30px;
			font-size: 25px;
			margin-top: 60px;

		}
		.add button{
			width: 60px;
			height: 40px;
			margin-left: 160px;
		}
	</style>
</head>
<body>
	<div class="add">
		<ul>
			<li>书名：<input input="text" class="name" id="ming"></li>
			<li>出版社：<input input="text" class="psw" id="chu"></li>
		</ul>
		<button class="dbtn">登录</button>
		<button class="zbtn">注册</button>
	</div>
</body>
<script type="text/javascript" src="jquery-3.1.1.js"></script>
<script type="text/javascript">
var dbtn = document.querySelector('.dbtn');
var zbtn = document.querySelector('.zbtn');
var name = document.querySelector('.name');
var psw = document.querySelector('.psw');

// zbtn.onclick = function(){
// 	var baseUrl="http://localhost:6500/milan";
// 	var xhr=new XMLHttpRequest();
// 	xhr.open("post",baseUrl);
// 	var obj = {
// 		username:name.value,	
// 		password:psw.value
// 	};
// 	console.log(obj);
// 	xhr.setRequestHeader("Content-Type","application/json");
// 	xhr.send(JSON.stringify(obj));
// }
//登录
 $(".dbtn").on("click",function () {

//        创建ajax获取登陆页面的数据
        var objs={
            username:$("#ming").val(),
            password:$("#chu").val()
        }
        $.ajax({
            type:"post",
            url:"http://localhost:6500/milan"+"/login",
            data:objs,
            success:function (data) {
                localStorage.dataId=data.uid;
                window.open("index.html");
            },
            error:function(){
            	console.log('未注册,请先注册');
            }
        })

    });

 //注册
 $('.zbtn').on("click",function(){
 	console.log(11);
 	var obja = {
 		username:$('#ming').val(),
 		password:$('#chu').val()
 	}
 	$.ajax({
 		type:"post",
 		url:"http://localhost:6500/milan",
 		data:obja,
 		success:function(){
 			console.log("注册成功");
 		}
 	})
 })






</script>
</html>